package cn.lger.icollege.controller;

import cn.lger.icollege.entity.Notice;
import cn.lger.icollege.service.NoticeService;
import cn.lger.icollege.util.PageableGenerator;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Code that Changed the World
 * Pro said
 * Created by Pro on 2018-04-21.
 */
@Controller
@RequestMapping("/common")
public class CommonController {

    @Resource
    private NoticeService noticeService;

    @GetMapping("/notices")
    @ResponseBody
    public Page<Notice> getNotices(Integer currentPage, Integer pageSize){
        return noticeService.findAll(PageableGenerator.pageOf(currentPage, pageSize, Sort.by(Sort.Direction.DESC, "createDate")));
    }

}
